﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GenerateDataBaseLibrary
{
    
    [AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
    sealed class SqlCredentialAttribute : Attribute
    {
        public CredentialMode CredentialMode { get; set; }
        public CredentialSource CredentialSource { get; set; }
        public char[] Separator { get; set; }
        public string FileStorage { get; set; }
        public string ConfigurationFilePath { get; set; }
        public SqlCredentialAttribute()
        {
            CredentialMode = GenerateDataBaseLibrary.CredentialMode.Windows;
        }
        public SqlCredentialAttribute(CredentialMode credentialMode, CredentialSource credentialSource)
        {
            this.CredentialMode = credentialMode;
            this.CredentialSource = credentialSource;
        }

        internal void ThrowException()
        {
            try
            {
                switch (CredentialSource)
                {
                    case CredentialSource.WindowPrompt:
                        break;
                    case CredentialSource.ConfigFile:
                        {
                            if (ConfigurationFilePath == string.Empty)
                            {
                                throw new SqlCredentialException("Configuation file path should be set");
                            }
                            break;
                        }

                    case CredentialSource.StorageFile:
                        if (FileStorage == string.Empty)
                        {
                            throw new SqlCredentialException("File storage path should set");
                        }
                        else if (Separator == null || Separator.Length == 0)
                        {
                            throw new SqlCredentialException("A separator character is needed");
                        }
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                throw;
            }
        }
       
    }

    public enum CredentialMode
    {Windows,SqlSever };
    public enum CredentialSource
    {WindowPrompt,ConfigFile,StorageFile};


    class SqlCredentialException:ApplicationException
    {
        public SqlCredentialException(string message)
            :base("Somme of the parameters shoudn't be empty")
        {
            
        }
    }

}
